<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-07-13 09:20:15
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-08-03 18:55:32
-->
<template>
   <!-- 头部 -->
    <div class="header">
      <!-- 第一行 -->
      <div class="header_top">
        <!-- 容器居中显示 -->
        <div class="wrapper">
          <div class="left">山西农业大学欢迎您</div>
          <div class="right">学校主页</div>
        </div>
      </div>
      <!-- / 第一行 -->
      <!-- 第二行 -->
      <div class="header_main">
        <div class="wrapper">
          <div class="logo">
            <img src="/resources/images/logo.png" alt="">
          </div>
          <ul class="menu">
            <li v-for="c in categories" 
            @click="toListHandler(c)"
            :key="c.id">{{c.name}}</li>
          </ul>
        </div>
      </div>
      <!-- /第二行 -->
      <!-- /容器居中显示 -->
    </div>
    <!-- /头部 -->
</template>
<script>
import { get } from '../../utils/request'
export default {
  data(){
    return {
      categories:[]
    }
  },
  methods:{
    // 跳转
    toListHandler(category){
      // 跳转
      this.$router.push({
        path:'/list',
        query:category
      })
    },
    // 加载栏目信息
    loadCategories(){
      let url = '/index/category/findAll'
      get(url).then(resp => {
        this.categories = resp.data;
      })
    }
  },
  created(){
    this.loadCategories();
  }
}
</script>
<style lang="scss" scoped>
// 头部样式
$color_primary:#028b39;
.header {
  .header_top {
    background-color: $color_primary;
    color: #fff;
    & > .wrapper::after {
      display:  block;
      content:'';
      clear:both;
    }
    .left,.right {
      line-height: 3em;
    }
    .left {
      float:left
    }
    .right {
      float: right;
    }

  }
  .header_main {
    padding: .5em 0 ;
    & > .wrapper {
      display: flex;
      justify-content: space-between;
      position:relative;
    }
    .logo {
      img {
        height:50px;
      }
    }
    ul.menu {
      position: absolute;
      bottom: 0;
      right: 0;
      & > li {
        float: left;
        padding: 0 .5em;
        cursor: pointer;
      }
      & > li.current ,
      & > li:hover{
        background-color: $color_primary;
        color:#fff;
      }
      
    }
  }
}
</style>